Skip to main content
Version: 5.2.0.1

Binary Data and Base64 encoded Strings

Orchestra has a data type to handle byte sequences. In the process model it is named binary while in the graphical mapping it is named Base64Binary because byte arrays are automatically encoded to strings using the Base64 encoding if a DOM tree containing it is serialized to an XML document.

Internally Orchestra uses the java classes esmd.util.Base64Binary and emds.util.Base64String B.ase64String is actually a subclass of Base64Binary so anywhere where an object of type Base64Binary is required you can use an instance of Base64String instead. In a graphical mapping elements of type base64Binary actually are instances of class Base64Binary .

Creating Objects of Base64Binary or Base64String

Typically, you create an instance of Base64Binary with a byte array as parameter.

byte[] bytes = ....
Base64Binary binaryData = new Base64Binary (bytes);

You may also create it from an InputStream:

InputStream dataStream = ....
int numberOfBytes = ....
binaryData = new Base64Binary(dataStream, numberOfBytes);

If you don't know the numberOfBytes you can simply set -1 as value of the parameter:

binaryData = new Base64Binary(dataStream, -1);

You typically construct an instance oBfase64String using a Base64 encoded string as parameter:

Base64String binaryData = new Base64String(base64text);

Typically, this constructor is used in an extended Java mapping (aka procedural mapping) if the value of a source element is Base64 encoded and you want to access its binary content. If you have a Reader containing the Base64 encoded text string (e.g. from a text file) you can use the according constructor:

Reader reader = ....
binaryData = new Base64String(reader);

Accessing binary data and Base64 encoded strings

To get the content of the Base64Binary or the Base64String you call the method getContentBytes():

bytes = binaryData.getContentBytes();

You may also write the binary content directly to an output stream:

OutputStream outputStream = ....
binaryData.writeContentData(outputStream);

If you need an InputStream to read the data you may simply write:

InputStream inputStream = binaryData.getContentData();

To get the content of thBease64Binary or thBease64String as Base64 encoded string you use the methogdetBase64EncodedString() :

String base64Text = binaryData.getBase64EncodedString();

The method toString() of Base64Binary returns getBase64EncodedString() . Therefore, in a Mapping you always can put a Base64Binary or a Base64String as value of a DOM node. If the created DOM tree is then serialized as XML the data is automatically rendered as Base64 encoded string.

If in a graphical mapping you access an element of type base64Binary it is actually an instance of class Base64Binary . Thus, you can invoke all the methods of this class, e.g. in a java function you may get the binary content using element.getContentBytes().

You may also write the content as Base64 encoded string to an output stream using the method writeBase64EncodedData:

binaryData.writeBase64EncodedData(outputStream);

This is a quite rare case because normally you want to write the original binary data using writeContentData.

Differences between Base64Binary and Base64String

Because Base64String is a subclass of Base64Binary it has all the constructors and methods of Base64Binary. Of course, if you already have a Base64 encoded string or a text file you create a Base64String from it using the appropriate constructors. But if you have a byte array or a byte stream you can choose to create a Base64Binary or a Base64String from the dataB.ase64String internally stores its data as Base64 encoded string while Base64Binary contains a byte array. If they logically represent the same binary data (they are equal according to the method equals) the Base64String needs more memory. So if you are working with very large data it is advisable to prefer Base64Binary.